package com.ruoyi.common.core.domain.model;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

/**
 * 用户信息
 *
 * @author ruoyi
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginUser implements UserDetails {
    private static final long serialVersionUID = 1L;

    /**
     * 用户唯一标识
     */
    private String token;

    /**
     * 用户id
     */
    private Long userid;

    /**
     * 所属部门id
     */
    private Long deptid;

    /**
     * 权限部门id数组、用户有什么部门的数据查看权限
     */
    private Set<Long> deptIds;

    /**
     * 用户名
     */
    private String username;

    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    /**
     * 登录IP地址
     */
    private String ipaddr;

    /**
     * 权限列表
     */
    private Set<String> permissions;

    /**
     * 角色ID列表
     */
    private Set<Long> roleIds;

    /**
     * 角色列表
     */
    private Set<String> roles;

    /**
     * 用户信息
     */
    private SysUser sysUser;

    /**
     * 用户所属部门信息
     */
    private SysDept sysDept;

    /**
     * 用户sessionKey
     */
    private String sessionKey;

    /**
     * 用户可见的资产维护部门
     */
    private Set<Long> userMaintenanceDeptIds;

    /**
     * 用户可见的资产所属部门
     */
    private Set<Long> userOwnDeptIds;

    public String getPassword(){
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public SysUser getUser()
    {
        return sysUser;
    }

    public Long getUserId(){
        return userid;
    }

    public Collection<? extends GrantedAuthority> getAuthorities()
    {
        return null;
    }

    public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions)
    {
        this.userid = userId;
        this.deptid = deptId;
        this.sysUser = user;
        this.permissions = permissions;
    }

}
